﻿using System;

class SequenceOfOperators

    // We are given integer number n, value v (v=0 or 1) and a position p. 
    // Write a sequence of operators that modifies n to hold the value v at the position p from the binary representation of n.
    // Example: n = 5 (00000101), p=3, v=1 - 13 (00001101), n = 5 (00000101), p=2, v=0 - 1 (00000001)

{
    static void Main()
    {
        Console.Write("Enter a number: ");
        int n = int.Parse(Console.ReadLine());
        Console.Write("Enter bit position: ");
        int p = int.Parse(Console.ReadLine());
        
        int mask = 1 << p;
        int maskIf = mask & n;
        int bit = maskIf >> p;
        
        Console.WriteLine("The value of the bit at position {0} is {1}", p, mask);
        Console.WriteLine("Before: {0} = {1}", n, Convert.ToString(n, 2).PadLeft(32, '0'));
        if (maskIf == 0)
        {
            n |= (1 << p);
        }
        else
        {
            n &= ~(1 << p);
        }
        Console.WriteLine("After: {0} = {1}", Convert.ToString(n, 10), Convert.ToString(n, 2).PadLeft(32, '0'));
    }
}

